<?php
namespace Zhub\Uri\Url;

use Zhub\DataStruct\Struct;

class UrlStruct extends Struct
{
	const SCHEME = 'scheme';

	const HOST = 'host';

	const PORT = 'port';

	const USERNAME = 'username';

	const PASSWORD = 'password';

	const PATH = 'path';

	const QUERY = 'query';

	const FRAGMENT = 'fragment';


	public function getScheme():string
	{
		return $this->get(self::SCHEME);
	}

	public function setScheme(string $scheme)
	{
        $this->set(self::SCHEME, $scheme);
	}

	public function getHost():string
	{
		return $this->get(self::HOST);
	}

	public function setHost(string $host)
	{
        $this->set(self::HOST, $host);
	}

	public function getPort():int
	{
		return $this->get(self::PORT);
	}

	public function setPort(int $port)
	{
	    $this->set(self::PORT, $port);
	}

	public function getUsername():?string
	{
		return $this->get(self::USERNAME);
	}

	public function setUsername(?string $username)
	{
        $this->set(self::USERNAME, $username);
	}

	public function getPassword():?string
	{
		return $this->get(self::PASSWORD);
	}

	public function setPassword(?string $password)
	{
        $this->set(self::PASSWORD, $password);
	}

	public function getPath():string
	{
		return $this->get(self::PATH);
	}

	public function setPath(string $path)
	{
        $path = '/' . trim($path, '\/');
        $this->set(self::PATH, $path);
	}

	public function getQuery():string
	{
		return $this->get(self::QUERY);
	}

	public function setQuery(?string $query)
	{
        $this->set(self::QUERY, strval($query));
	}

	public function getFragment():string
	{
		return $this->get(self::FRAGMENT);
	}

	public function setFragment(?string $fragment)
	{
        $this->set(self::FRAGMENT, strval($fragment));
	}

	public static function initialize():array
	{
		return [
			self::SCHEME => 'http',
			self::HOST => '',
			self::PORT => 80,
			self::USERNAME => '',
			self::PASSWORD => '',
			self::PATH => '/',
			self::QUERY => '',
			self::FRAGMENT => '',
	
		];
	}

	public function toString(): string
    {
        return UrlHandle::resolve($this);
    }

}
